package com.yuncheng.spcyApi.service.impl;

import com.yuncheng.spcyApi.dto.FlowJobHistoryDto;
import com.yuncheng.spcyApi.vo.flow.SpcyJobSxVo;
import com.yuncheng.spcyApi.vo.flow.SpcyJobXqVo;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuncheng.common.base.service.impl.BaseServiceImpl;
import com.yuncheng.spcyApi.constant.common.SpcyConstant;
import com.yuncheng.spcyApi.entity.SpcySqsxJob;
import com.yuncheng.spcyApi.mapper.SpcySqsxJobMapper;
import com.yuncheng.spcyApi.service.ISpcySqsxJobService;
import com.yuncheng.spcyApi.vo.common.PageVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description: 审评查验申请事项的流转记录
 * @Author: csx
 * @Date: 2023-03-01
 * @Version: V1.0
 */
@Service
public class SpcySqsxJobServiceImpl extends BaseServiceImpl<SpcySqsxJobMapper, SpcySqsxJob> implements ISpcySqsxJobService {

    @Resource
    private SpcySqsxJobMapper spcySqsxJobMapper;

    @Override
    public String getSqsxLzjlHjmc(String sqsxId) {
        List<SpcySqsxJob> dbList = list(new LambdaQueryWrapper<SpcySqsxJob>()
                .eq(SpcySqsxJob::getFpid, sqsxId)
                .eq(SpcySqsxJob::getFblzt, SpcyConstant.BLZT_DB));
        String hjmc = "";
        if (CollectionUtils.isNotEmpty(dbList)){
            hjmc = dbList.get(0).getFhjmc();
        }
        return hjmc;
    }

    @Override
    public long getDbJobListSize(PageVo pageVo, String userid, String flcmc) {
        Page<SpcySqsxJob> page = new Page<>(pageVo.getPageNo(), pageVo.getPageSize());

        Page<SpcySqsxJob> pageList = page(page, new LambdaQueryWrapper<SpcySqsxJob>()
                .like(SpcySqsxJob::getFdbrid, userid)
                .like(SpcySqsxJob::getFlcmc, flcmc)
                .ne(SpcySqsxJob::getFblzt, SpcyConstant.BLZT_YB));

        return pageList.getTotal();
    }

    @Override
    public List<SpcySqsxJob> getJobListByHjmc(String pid, String fhjmc, String flcmc) {
        return list(new LambdaQueryWrapper<SpcySqsxJob>()
                .eq(SpcySqsxJob::getFpid, pid)
                .eq(StringUtils.isNotBlank(fhjmc), SpcySqsxJob::getFhjmc, fhjmc)
                .like(StringUtils.isNotBlank(flcmc), SpcySqsxJob::getFlcmc, flcmc)
                .orderByDesc(SpcySqsxJob::getFfssj));
    }

    @Override
    public List<SpcySqsxJob> selectJobListByFpidInOrder(String pid, String flcmc) {
        return spcySqsxJobMapper.selectJobListByFpid(pid, null, flcmc, "是");
    }

    @Override
    public List<SpcySqsxJob> selectJobListByFpidInNotOrder(String pid, String fhjmc, String flcmc) {
        return spcySqsxJobMapper.selectJobListByFpid(pid, fhjmc, flcmc, null);
    }

    @Override
    public SpcyJobXqVo selectJobInfoById(String id) {
        return spcySqsxJobMapper.selectJobInfoById(id);
    }

    @Override
    public List<String> selectDbIdByFpidAndFhjmc(String fpid, String fhjmc) {
        return spcySqsxJobMapper.selectDbIdByFpidAndFhjmc(fpid, fhjmc);
    }

    @Override
    public List<FlowJobHistoryDto> selectHistoryListByFpidAndFlcmc(String fpid, String flcmc) {
        return spcySqsxJobMapper.selectHistoryListByFpidAndFlcmc(fpid, flcmc);
    }

    @Override
    public List<SpcyJobSxVo> selectDbJobSxListByFpid(String fpid, String fhjmc, String flcmc) {
        return spcySqsxJobMapper.selectDbJobSxListByFpid(fpid, fhjmc, flcmc);
    }


}
